package com.soyotec.algorithm.compare;

import com.soyotec.algorithm.solution.ValueWrapSolution;

public abstract class AbstractComparator implements Comparator<ValueWrapSolution>{
    /**
     * 两个方案比较出较好的一个方案
     * @param solution1 较好的方案
     * @param solution2 需要比较的方案
     * @return
     */
    @Override
    public ValueWrapSolution compareSolution(ValueWrapSolution solution1, ValueWrapSolution solution2) {
        if(solution1 == null){
            return solution2;
        } else {
            double obj1 = solution1.getObjectiveAndPenalty();
            double obj2 = solution2.getObjectiveAndPenalty();
            if(obj2 < obj1){
                return solution2;
            }
            return solution1;
        }
    }
}
